<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>C语言程序设计诊断专家系统</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
    type="text/css">
  <link rel="stylesheet" href="https://static.pingendo.com/bootstrap/bootstrap-4.1.3.css">
</head>

<body>
  <nav class="navbar navbar-expand-lg bg-dark navbar-dark">
    <div class="container"> <button class="navbar-toggler navbar-toggler-right border-0 p-0" type="button"
        data-toggle="collapse" data-target="#navbar14">
        <p class="navbar-brand mb-0 text-white">
          <i class="fa d-inline fa-lg fa-stop-circle"></i> BRAND </p>
      </button>
      <div class="collapse navbar-collapse" id="navbar14">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item"> <a class="nav-link" href="/">问答系统</a> </li>
          <li class="nav-item"> <a class="nav-link" href="/Code">代码检测</a> </li>
        </ul>
        <p class="d-none d-md-block lead mb-0  text-white"> <i class="fa d-inline fa-lg fa-stop-circle"></i>
          <b>C语言程序设计诊断专家系统</b> </p>
        <ul class="navbar-nav ml-auto">
            <li class="nav-item"> <a class="nav-link" href="javascript:Back()">反馈并帮助我们完善知识库</a> </li>
        </ul>
      </div>
    </div>
  </nav>
  <div class="text-center bg-dark text-white py-1">
    <div class="container">
      <div class="row">
        <div class="col-md-6">
          <div class="card text-center" style="height: 500px">
            <div class="card-header text-dark">我没有错误代码</div>
            <div class="card-body text-dark">
              <ul class="nav nav-pills">
                <li class="nav-item"> <a class="active nav-link" href="" data-toggle="pill"
                    data-target="#tabone">问题描述</a> </li>
                <li class="nav-item"> <a href="" class="nav-link" data-toggle="pill" data-target="#tabtwo">对目标问题的操作</a>
                </li>
              </ul>
              <div class="tab-content mt-2" style="height: 300px">
                <div class="tab-pane fade show active" id="tabone" role="tabpanel">
                  {{Question}}
                </div>
                <div class="tab-pane fade" id="tabtwo" role="tabpanel">
                  <form>
                    {{Operate}}
                  </form>
                </div>
              </div><a href="#" class="btn btn-primary" onclick="GetResult()">开始检测</a>
            </div>
          </div>
        </div>
        <div class="col-md-6">
          <div class="card text-center" style="height: 500px">
            <div class="card-header text-dark">我有编译错误代码</div>
            <div class="card-body text-dark">
              <div class="form-group">
                <label for="errorCode">请输入错误代码:</label>
                <input type="text" class="form-control" id="errorCode" name="errorCode" placeholder="c1003">
              </div>
              <a href="#" class="btn btn-primary" onclick="CheckCode()">开始检测</a>
              <br><br><br><br><br>
              <div class="card">
                <div class="card-body">
                  <h4 class="card-title">当前知识库信息量</h4><br>
                  <p class="card-text">错误代码：{{CountError}}条</p>
                  <p class="card-text">运行时问题：{{CountQurstion}}条</p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="row">
      </div>
    </div>
  </div>
  <div class="py-3 bg-dark text-light" >
    <div class="container">
      <div class="row">
        <div class="col-md-12 text-center"> <i class="d-block fa fa-stop-circle mb-3 text-muted fa-3x"></i>
          <p> <a href="https://goo.gl/maps/AUq7b9W7yYJ2" target="_blank"> C语言程序设计诊断专家系统 <br>人工智能课程设计</a> </p>
          <p> <a href="tel:+246 - 542 550 5462">162班 1600802046 李怡龙</a> </p>
          <p class="mb-0"> <a href="mailto:leeli@live.cn">leeli@live.cn</a> </p>
        </div>
      </div>
      <div class="row">
        <div class="col-md-12 d-flex align-items-center justify-content-center my-3"> <a href="https://www.cnblogs.com/lee-li/">
            <i class="d-block fa fa-bold text-muted fa-lg mr-2"></i>
          </a> <a href="https://github.com/leeli73/">
            <i class="d-block fa fa-github text-muted fa-lg mx-2"></i>
          </a> 
         </div>
      </div>
      <div class="row">
        <div class="col-md-12 text-center">
          <p class="mb-0">计算机技术与应用系</p>
        </div>
      </div>
    </div>
  </div>

  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title" id="myModalLabel">
            错误代码解析
          </h4>
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
              &times;
            </button>
        </div>
        <div class="modal-body">
          <table class="table table-bordered">
            <thead>
              <tr>
                <th>错误代码</th>
                <th>中文对照</th>
                <th>解决建议</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td id="table_code">NULL</td>
                <td id="table_chinese">NULL</td>
                <td id="table_way">NULL</td>
              </tr>
            </tbody>
          </table>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">关闭
          </button>
        </div>
      </div><!-- /.modal-content -->
    </div><!-- /.modal -->
  </div>

  <div class="modal fade" id="myModalResult" tabindex="-1" role="dialog" aria-labelledby="myModalLabelResult" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title" id="myModalLabelResult">
            推测结果
          </h4>
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
              &times;
            </button>
        </div>
        <div class="modal-body">
          <table class="table table-bordered">
            <thead>
              <tr>
                <th>问题描述代码</th>
                <th>造成原因</th>
                <th>解决建议</th>
              </tr>
            </thead>
            <tbody id="table_result">
              <tr>
                <td id="table_questioncode">NULL</td>
                <td id="table_reason">NULL</td>
                <td id="table_suggest">NULL</td>
              </tr>
            </tbody>
          </table>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal" onclick="test()">关闭
          </button>
        </div>
      </div><!-- /.modal-content -->
    </div><!-- /.modal -->
  </div>

  <div class="modal fade" id="myModalback" tabindex="-1" role="dialog" aria-labelledby="myModalLabelback" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <h4 class="modal-title" id="myModalLabelback">
              反馈并帮助完善知识库
            </h4>
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                &times;
              </button>
          </div>
          <div class="modal-body">
              <div class="form-group">
                  <label for="errorCode">错误描述:</label>
                  <input type="text" class="form-control" id="newQues" name="miaoshu">
              </div>
              <div class="form-group">
                  <label for="errorCode">进行的操作:</label>
                  <input type="text" class="form-control" id="newOp" name="caozuo">
              </div>
              <div class="form-group">
                  <label for="errorCode">我的解决方法:</label>
                  <input type="text" class="form-control" id="newWay" name="fangfa">
              </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="AddNew()">提交</button>
          </div>
        </div><!-- /.modal-content -->
      </div><!-- /.modal -->
    </div>

  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
    integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
    crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"
    integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
    crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"
    integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
    crossorigin="anonymous"></script>
</body>
<script>
  function CheckCode() {
    var code = document.getElementById("errorCode").value
    if (code == "") {
      alert("请输入正确的错误代码!")
      return
    }
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        //alert(xmlhttp.responseText);
        temp = xmlhttp.responseText.split("<br>");
        document.getElementById("table_code").innerText = temp[0];
        document.getElementById("table_chinese").innerText = temp[1];
        document.getElementById("table_way").innerText = temp[2];
        $('#myModal').modal();
      }
    }
    var data = "code=" + code;
    xmlhttp.open("POST", "/CheckCode", true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.send(data);
  }
  function Back()
  {
    $('#myModalback').modal();
  }
  function GetResult(){
    var question = ""
    var operate = ""
    var temp1 = 10001
    var temp2 = 20001
    for(var i = 0;i<{{QuestionCount}};i++)
    {
      if(document.getElementById("code"+temp1.toString()).checked)
      {
        question = document.getElementById("code"+temp1.toString()).value
        break
      }
      temp1++
    }
    for(var i = 0;i<{{OperateCount}};i++)
    {
      if(document.getElementById("code"+temp2.toString()).checked)
      {
        operate = operate + document.getElementById("code"+temp2.toString()).value + ","
      }
      temp2++
    }
    if(question == "" || operate == "")
    {
      alert("请正确选择描述及操作!")
      return
    }
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        //alert(xmlhttp.responseText);
        //$('#myModalResult').modal();
        var temp1 = xmlhttp.responseText.split("|@|")
        var count = temp1[0]
        if(count != "0")
        {
          var temp2 = temp1[1].split("|#|")
          var code = ""
          for(var i=0;i<temp2.length;i++)
          {
            if(temp2[i] != "")
            {
              var temp3 = temp2[i].split("|$|")
              code = code + "<tr><td>"+ question +"</td><td>"+ temp3[0] +"</td><td>"+temp3[1]+"</td></tr>"
            }
          }
          document.getElementById("table_result").innerHTML = code
        }
        $('#myModalResult').modal();
      }
    }
    var data = "question=" + question + "&operate=" + operate;
    console.log(data)
    xmlhttp.open("POST", "/GetResult", true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.send(data);
  }
  function AddNew()
  {
    var newQ = document.getElementById("newQues").value
    var newO = document.getElementById("newOp").value
    var newW = document.getElementById("newWay").value
    if (newQ == "" && newO == "" && newW == "") {
      alert("请输入正确的信息!")
      return
    }
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        alert(xmlhttp.responseText)
      }
    }
    var data = "newq=" + newQ +"&newo=" + newO + "&neww=" + newW;
    xmlhttp.open("POST", "/NewRule", true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.send(data);
  }
  function test()
  {
    location.reload();
  }
</script>

</html>